/*
 * @Author: your name
 * @Date: 2020-05-20 14:59:51
 * @LastEditTime: 2020-06-16 10:56:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \IM_Web\im_web\src\main.js
 */
import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'
// import 'iview/dist/styles/iview.css';
import './iview/index.js'

import './assets/app.css'

import Contextmenu from "vue-contextmenujs"
Vue.use(Contextmenu);

import http from './http.js'
Vue.prototype.http = http
// Vue.use(element)
// import { Button, Table } from 'iview';
// Vue.component('Button', Button);
// Vue.component('Table', Table);

// RSA加密
// import { JSEncrypt } from 'jsencrypt'
// Vue.prototype.$getCode = (params) => {
//     return new Promise((resolve) => {
//         let encrypt = new JSEncrypt()
//         encrypt.setPrivateKey('-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvF5p84FCcNfAD9VmQ93IZa9XnyWtYmGor5CVA3MKr4+soQ1W1AxQ7WAS3xabalGKSpbHV4r/Vc+gLbUrUE1LnrTxQInq1BWgQkxlmSa4VJx5SYIfyTnSp73WkFWYYgtR7TP+4yelVeCmTCOh5xXOe30Rs67IX2wt1BSWOPNdg6TnddUpmnZ0so3mZ/kkUEIAkGlPVfHVZhzckuGB9suibf/PsJBVy34TqbLxRy1JWj4W08YeCcXnS9UD1wmKnh1v5OOLnc+AvhUz+hpfZ23B7PVrO519CMftXVgdeBD0CdA+dlllmrN7IGRVgxqgcO2pBXrCnkDEKtt5XTnxKtuF1IS0vzlNPGkcEherPkCxV+d/p0JMU/yBTHLkKr2oRPdqAfPnVOKW2k8tAoQPRkEVQ1janzntRC6V2sSmsqu1OWMW6GGlbopIvXwKGr31JRtUzbnrp0Pt8sIXMYTTFfJILi3A7OFm5gkVGJ+TGe0GbH63v2DsiN1k9W53wqbBbl3LWf1oOqmihaS1XLUvlOY4YUBz2QmH8snsjeGhdU+rMMfSmBxermjpWvICyOZm/aO9XETLCAm3n8/SGQ8F63sTaVijlwICmkPMr4qu5lctNJrVXmpDSjMVCLqi71qliBRu/7YwvAbOt+05ceWgjQurtgXCuuE3SMRGDF/scnE+jyMCAwEAAQ==-----END PUBLIC KEY-----')
//         let data = encrypt.encrypt(params)
//         // console.log(params)
//         resolve(data)
//     })
// }

router.beforeEach((to, from, next) => {
    if (to.matched.length === 0) {
        from.path ? next({ path: from.path }) : next('/')
    } else {
        if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
            if (sessionStorage.getItem('t')) { // 通过vuex state获取当前的token是否存在
                next()
            } else {
                next({
                    path: '/login'
                    // query: { redirect: to.fullPath } // 将跳转的路由path作为参数，登录成功后跳转到该路由
                })
            }
        } else {
            next()
        }
    }
})

Vue.config.productionTip = false

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
